package com.cupk.mapper;

import com.cupk.entity.Admin;
import org.apache.ibatis.annotations.*;

import java.util.List;


import com.cupk.dto.AdminDto;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
public interface AdminMapper {

    @Select("SELECT * FROM admin_tb WHERE id_card=#{idCard} AND password=#{password}")
    Admin getUserByUsernameAndPassword(@Param("idCard") String idCard, @Param("password") String password);

    @Select("SELECT * FROM admin_tb WHERE tele=#{tele}")
    Admin getUserByTele(String tele);

    @Select("SELECT * FROM admin_tb WHERE id_card=#{idCard}")
    Admin getUserByIdcard(@Param("idCard") String idCard);

    @Select("SELECT name FROM admin_tb WHERE tele=#{tele}")
    String getAdminName(String tele);

    @Insert("INSERT INTO admin_tb (id, name, tele, level, password, state, id_card, head_image_url) " +
            "VALUES (#{id}, #{name}, #{tele}, #{level}, #{password}, #{state}, #{idCard}, #{headImageUrl})")
    int insertAdmin(Admin admin);

    @Update("UPDATE admin_tb SET state = 2, level = 2 WHERE tele = #{tele}")
    void updateAdminStateAndLevelOnLevelTwo(@Param("tele") String tele);

    @Update("UPDATE admin_tb SET state = 2, level = 3 WHERE tele = #{tele}")
    void updateAdminStateAndLevelOnLevelThree(@Param("tele") String tele);

    @Select("SELECT * FROM admin_tb")
    List<Admin> getAllAdmin();




    /**
     * "相关同事"分页查询
     * @param id 管理员编号
     * @param name 管理员姓名
     * @param tele 管理员联系方式
     * @param page 起始页码
     * @param pageSize 每页返回的数据条目数
     * @return
     */
    List<AdminDto> getAdminPage(
            @Param("id") Integer id,
            @Param("name") String name,
            @Param("tele") String tele,
            @Param("page") int page,
            @Param("pageSize") int pageSize
    );

    /**
     * "相关同事"分页查询的总记录
     * @param id 管理员编号
     * @param name 管理员姓名
     * @param tele 管理员联系方式
     * @return
     */
    int getAdminCount(
            @Param("id") Integer id,
            @Param("name") String name,
            @Param("tele") String tele
    );
}
